<template>
  <el-dialog title="新增角色" :visible="showDialog" @close="btnCancel">
    <el-form ref="addFrom" label-width="120px" :model="addFrom" :rules="addRules">
      <el-form-item label="角色名称" prop="name">
        <el-input v-model.trim="addFrom.name" placeholder="2-10个字符" style="width: 80%;" size="mini" />
      </el-form-item>
      <el-form-item label="启用">
        <el-switch
          v-model="addFrom.state"
          :active-value="1"
          :inactive-value="0"
        />
      </el-form-item>
      <el-form-item label="角色描述" prop="description">
        <el-input v-model.trim="addFrom.description" placeholder="2-10个字符" style="width: 80%;" size="mini" />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-row style="width:100%;" type="flex" justify="center">
        <el-button type="primary" size="mini" style="margin-right:50px" @click="btnCancel">取消</el-button>
        <el-button type="primary" size="mini" @click="btnOK">确认</el-button>
      </el-row>
    </template>
  </el-dialog>
</template>
<script>
import { addRoleAPI } from '@/api/role'
export default {
  name: 'AddDept',
  props: {
    showDialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      managerList: [],
      addFrom: {
        name: '',
        description: '',
        state: 0
      },
      addRules: {
        description: [{ required: true, message: '角色描述不能为空', trigger: 'change' }],
        name: [{ required: true, message: '角色名称不能为空', trigger: 'change' }]
      }
    }
  },
  methods: {
    btnCancel() {
      this.$emit('update:showDialog', false)
      this.$refs.addFrom.resetFields()
    },
    async btnOK() {
      await this.$refs.addFrom.validate()
      await addRoleAPI(this.addFrom)
      this.btnCancel()
      this.$emit('updateDept')
    }
  }
}
</script>
<style>
</style>
